package com.ruoyi.module.service.impl;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.module.mapper.UserWordRecordMapper;
import com.ruoyi.module.domain.UserWordRecord;
import com.ruoyi.module.service.IUserWordRecordService;
import com.ruoyi.common.utils.SecurityUtils;

/**
 * 用户单词学习记录Service业务层处理
 * 
 * @author ruoyi
 */
@Service
public class UserWordRecordServiceImpl implements IUserWordRecordService 
{
    @Autowired
    private UserWordRecordMapper userWordRecordMapper;

    /**
     * 查询用户单词学习记录
     */
    @Override
    public UserWordRecord selectUserWordRecordById(Long id)
    {
        return userWordRecordMapper.selectUserWordRecordById(id);
    }

    /**
     * 查询用户单词学习记录列表
     */
    @Override
    public List<UserWordRecord> selectUserWordRecordList(UserWordRecord userWordRecord)
    {
        // 自动设置当前用户ID
        if (userWordRecord.getUserId() == null) {
            userWordRecord.setUserId(SecurityUtils.getUserId());
        }
        return userWordRecordMapper.selectUserWordRecordList(userWordRecord);
    }

    /**
     * 新增用户单词学习记录
     */
    @Override
    public int insertUserWordRecord(UserWordRecord userWordRecord)
    {
        // 自动设置当前用户ID
        if (userWordRecord.getUserId() == null) {
            userWordRecord.setUserId(SecurityUtils.getUserId());
        }
        return userWordRecordMapper.insertUserWordRecord(userWordRecord);
    }

    /**
     * 修改用户单词学习记录
     */
    @Override
    public int updateUserWordRecord(UserWordRecord userWordRecord)
    {
        return userWordRecordMapper.updateUserWordRecord(userWordRecord);
    }

    /**
     * 批量删除用户单词学习记录
     */
    @Override
    public int deleteUserWordRecordByIds(Long[] ids)
    {
        return userWordRecordMapper.deleteUserWordRecordByIds(ids);
    }

    /**
     * 删除用户单词学习记录信息
     */
    @Override
    public int deleteUserWordRecordById(Long id)
    {
        return userWordRecordMapper.deleteUserWordRecordById(id);
    }

    /**
     * 查询错词记录
     */
    @Override
    public List<UserWordRecord> selectErrorWordRecords(UserWordRecord userWordRecord)
    {
        // 自动设置当前用户ID
        if (userWordRecord.getUserId() == null) {
            userWordRecord.setUserId(SecurityUtils.getUserId());
        }
        return userWordRecordMapper.selectErrorWordRecords(userWordRecord);
    }

    /**
     * 批量插入单词记录
     */
    @Override
    public int batchInsertUserWordRecord(List<UserWordRecord> list)
    {
        // 自动设置当前用户ID
        Long userId = SecurityUtils.getUserId();
        for (UserWordRecord record : list) {
            if (record.getUserId() == null) {
                record.setUserId(userId);
            }
        }
        return userWordRecordMapper.batchInsertUserWordRecord(list);
    }
}

